package pe.indra.log.listener.servlet;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * Servlet implementation class LogServlet
 */
public class LogServlet extends HttpServlet {
	static Logger logger = Logger.getLogger(LogServlet.class.getName());
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LogServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {			
			ObjectInputStream dataInput = new ObjectInputStream(request.getInputStream());
			String cadenaDatos;			
			cadenaDatos = (String)dataInput.readObject();			
			logger.info(cadenaDatos);
			logger.info(cadenaDatos);
			ObjectOutputStream dataOutput = new ObjectOutputStream(response.getOutputStream());			
			dataOutput.writeObject("1");			
			dataOutput.flush();
			dataInput.close();
			dataOutput.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
